--[[ 恐龙快打脚本,显示血量和暴击,自制的简单实例

  By setycyas @2025-06-30
]]

--防止重复运行
if (_G.game) then
  print('Dino.lua is running!')
  return
end
--模块调用
local myMame = require('MyMame')
-- 本模块,定义时设定基本参数
local GAME = {
  -- 脚本名,提示与分辨用
  NAME = "dino_autoboot",
  --
  -- 地址,暴击和血量,这里只记录1p
  POWER_ADDR = 0xFFB33A,
  HP_ADDR = 0xFFB2E1,
  -- 显示数据的位置坐标
  POWER_X = 0.3,
  POWER_Y = 0.11,
  HP_X = 0.335,
  HP_Y = 0.07,
  -- 字体颜色
  FONT_COLOR = 0xFFffff00,
  
  -- 更新模块参数函数
  refreshModule = function(self)
    myMame.gameName = self.NAME
    myMame.screenIndex = ':screen'
    myMame.mem = manager.machine.devices[':maincpu'].spaces['program']
  end
}
-- 更新模块参数
GAME:refreshModule()

-- 显示暴击
function GAME.showPower()
  local power = string.format("%X", myMame.mem:read_u8(GAME.POWER_ADDR))
  myMame.ui_container:draw_text(
    GAME.POWER_X, GAME.POWER_Y, 
    power, GAME.FONT_COLOR
  )
end

--显示血量
function GAME.showHp()
  local hp = string.format("%d", myMame.mem:read_u8(GAME.HP_ADDR))
  myMame.ui_container:draw_text(
    GAME.HP_X, GAME.HP_Y, 
    hp, GAME.FONT_COLOR
  )
end

-- 主函数,绑定后每一帧执行一次该函数
function GAME.Main()
  
  GAME.showPower()
  GAME.showHp()

end

-- [[运行]]

-- 绑定每一帧执行的函数
--myMame.debugRunPerFrame(GAME.Main, 'dino')
myMame.runPerFrame(GAME.Main, 'dino')
-- 导出到全局变量
_G.game = GAME

return GAME
